1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-09-02 19:52:32 +02:00
* remove some key usage from core, refactor Operations.apply

* undeprecate some methods

* convert more key usage to paths

* update deprecations

* convert selection commands to use all paths

* refactor word boundary selection logic

* convert many at-range commands to use paths

* convert wrapBlock and wrapInline to not use keys

* cleanup

* remove chainability from editor

* simplify commands, queries and middleware

* convert deleteAtRange

* remove key usage from schema, deprecate *ByKey methods

* migrate *ByKey tests, remove index from *ByPath signatures

* rename at-current-range tests

* deprecate mode key usage, migrate more tests away from keys

* deprecate range and point methods which rely on keys to work

* refactor insertBlock, without fixing warnings

* add pathRef/pointRef, fix insertBlock/Inline deprecations, work on insertFragment

* refactor insertFragment

* get rich-text example rendering

* fix lint

* refactor query files, fix more tests

* remove unused queries, refactor others

* deprecate splitDescendantsByPath

* merge master

* add typescript, convert slate, slate-hyperscript, slate-plain-serializer

* add Point, Path, Range, Annotation tests

* add Annotation, Change, Element, Fragment, Mark, Range, Selection, Value interfaces tests

* add Operation and Text tests

* add Node tests

* get operations and normalization tests working for slate

* get *AtPath command tests passing

* rename *AtPath command tests

* rename

* get *AtPoint tests working

* rename

* rename

* add value queries tests

* add element, mark and path queries tests

* convert most on-selection tests

* convert on-selection commands

* rename

* get addMarks and delete commands working

* rename

* rename

* rename

* refactor value.positions(), work on delete tests

* progress on delete tests

* more delete work

* finish delete tests

* start converting to at-based commands

* restructure query tests

* restructure operations tests

* more work converting to multi-purpose commands

* lots of progress on converting to at-based commands

* add unwrapNodes

* remove setValue

* more progress

* refactor node commands to use consistent matching logic

* cleanup, get non-fragment commands passing

* remove annotations and isAtomic

* rename surround/pluck to cover/uncover

* add location concept, change at-path to from-path for iterables

* refactor batches

* add location-based queries

* refactor hanging logic

* more location query work

* renaming

* use getMatch more

* add split to wrap/unwrap

* flip levels/ancestors ordering

* switch splitNodes to use levels

* change split to always:false by default

* fix tests

* add more queries tests

* fixing more delete logic

* add more splitNodes tests

* get rest of delete tests passing

* fix location-based logic in some commands

* cleanup

* get previous packages tests passing again

* add slate-history package

* start slate-schema work

* start of react working

* rendering fixes

* get rich and plain text examples working

* get image example working with hooks and dropping

* refactor onDrop to be internal

* inline more event handlers

* refactor lots of event-related logic

* change rendering to use render props

* delete unused stuff

* cleanup dom utils

* remove unused deps

* remove unnecessary packages, add placeholder

* remove slate-react-placeholder package

* remove unused dep

* remove unnecessary tests, fix readonly example

* convert checklists example

* switch to next from webpack

* get link example working

* convert more examples

* preserve keys, memoized leafs/texts, fix node lookup

* fix to always useLayoutEffect for ordering

* fix annotations to be maps, memoize elements

* remove Change interface

* remove String interface

* rename Node.entries to Node.nodes

* remove unnecessary value queries

* default to selection when iterating, cleanup

* remove unused files

* update scroll into view logic

* fix undoing, remove constructor types

* dont sync selection while composing

* add workflows

* remove unused deps

* convert mentions example

* tweaks

* convert remaining examples

* rename h to jsx, update schema

* fix schema tests

* fix slate-schema logic and tests

* really fix slate-schema and forced-layout example

* get start of insertFragment tests working

* remove Fragment interface

* remove debugger

* get all non-skipped tests passing

* cleanup deps

* run prettier

* configure eslint for typescript

* more eslint fixes...

* more passing

* update some docs

* fix examples

* port windows undo hotkey change

* fix deps, add basic firefox support

* add event overriding, update walkthroughs

* add commands, remove classes, cleanup examples

* cleanup rollup config

* update tests

* rename queries tests

* update other tests

* update walkthroughs

* cleanup interface exports

* cleanup, change mark transforms to require location

* undo mark transform change

* more

* fix tests

* fix example

* update walkthroughs

* update docs

* update docs

* remove annotations

* remove value, move selection and children to editor

* add migrating doc

* fix lint

* fix tests

* fix DOM types aliasing

* add next export

* update deps, fix prod build

* fix prod build

* update scripts

* update docs and changelogs

* update workflow and pull request template
This commit is contained in:
Ian Storm Taylor
2019-11-27 20:54:42 -05:00
committed by GitHub
parent 02b87d5968
commit 4ff6972096
2367 changed files with 45706 additions and 80698 deletions

View File

@@ -1,103 +0,0 @@
/* eslint-disable no-console */
import chalk from 'chalk'
import figures from 'figures'
import emojis from 'emojis'
import baseline from '../../tmp/benchmark-baseline'
import comparison from '../../tmp/benchmark-comparison'
import { existsSync } from 'fs'
/**
* Constants.
*/
let THRESHOLD = 0.333
const configPath = '../../tmp/benchmark-config.js'
if (existsSync(configPath)) {
const alternative = require(configPath).THRESHOLD
if (typeof alternative === 'number' && alternative > 0) {
THRESHOLD = alternative
}
}
/**
* Print.
*/
console.log()
console.log(` benchmarks`)
baseline.forEach((suite, i) => {
console.log(` ${suite.name}`)
suite.benchmarks.forEach((base, j) => {
const compared = { user: {}, hr: {} }
for (const key of Object.keys(compared)) {
const comp = comparison[i].benchmarks[j]
if (!comp) return
const b = base.iterations / base[key] * 1000
const c = comp.iterations / comp[key] * 1000
const balancePercent =
b > c ? Math.round(Math.abs(b - c) / c * 100) : (c - b) / b * 100
const output = `${b.toFixed(2)} -> ${c.toFixed(2)} ops/sec`
compared[key].baseOutput = output
compared[key].percentOutput = `${balancePercent.toFixed(2)}% ${
c > b ? 'faster' : 'slower'
}`
compared[key].percentValue = balancePercent
compared[key].b = b
compared[key].c = c
compared[key].isFaster = c > b
if (balancePercent > 1000) {
compared[key].percentOutput += emojis.unicode(' :scream: ')
} else if (balancePercent > 100) {
if (c > b) {
compared[key].percentOutput += emojis.unicode(' :raised_hands: ')
} else {
compared[key].percentOutput += emojis.unicode(' :worried: ')
}
}
}
const { user, hr } = compared
if (
user.percentValue < THRESHOLD * 100 &&
hr.percentValue < THRESHOLD * 100
) {
console.log(
chalk.grey(
` ${figures.tick} ${base.name}: ${user.baseOutput} (${
user.percentOutput
})`
)
)
return
}
if (user.isFaster === hr.isFaster) {
if (user.isFaster) {
console.log(chalk.green(` ${figures.star} ${base.name}:`))
console.log(
` user: ${user.baseOutput} (${user.percentOutput})`
)
console.log(` real: ${hr.baseOutput} (${hr.percentOutput})`)
return
}
console.log(chalk.red(` ${figures.cross} ${base.name}:`))
console.log(
` user: ${user.baseOutput} (${user.percentOutput})`
)
console.log(` real: ${hr.baseOutput} (${hr.percentOutput})`)
return
}
console.log(chalk.red(` ${figures.questionMarkPrefix} ${base.name}:`))
console.log(` user: ${user.baseOutput} (${user.percentOutput})`)
console.log(` real: ${hr.baseOutput} (${hr.percentOutput})`)
})
})
console.log()

55
support/fixtures.js Normal file
View File

@@ -0,0 +1,55 @@
import fs from 'fs'
import { basename, extname, resolve } from 'path'
export const fixtures = (...args) => {
let fn = args.pop()
let options = { skip: false }
if (typeof fn !== 'function') {
options = fn
fn = args.pop()
}
const path = resolve(...args)
const files = fs.readdirSync(path)
const dir = basename(path)
const d = options.skip ? describe.skip : describe
d(dir, () => {
for (const file of files) {
const p = resolve(path, file)
const stat = fs.statSync(p)
if (stat.isDirectory()) {
fixtures(path, file, fn)
}
if (
stat.isFile() &&
file.endsWith('.js') &&
!file.startsWith('.') &&
// Ignoring `index.js` files allows us to use the fixtures directly
// from the top-level directory itself, instead of only children.
file !== 'index.js'
) {
const name = basename(file, extname(file))
// This needs to be a non-arrow function to use `this.skip()`.
it(`${name} `, function() {
const module = require(p)
if (module.skip) {
this.skip()
return
}
fn({ name, path, module })
})
}
}
})
}
fixtures.skip = (...args) => {
fixtures(...args, { skip: true })
}

View File

@@ -1,26 +0,0 @@
import factory from './factory'
import slate from '../../packages/slate/package.json'
import slateBase64Serializer from '../../packages/slate-base64-serializer/package.json'
import slateDevEnvironment from '../../packages/slate-dev-environment/package.json'
import slateHotkeys from '../../packages/slate-hotkeys/package.json'
import slateHtmlSerializer from '../../packages/slate-html-serializer/package.json'
import slateHyperscript from '../../packages/slate-hyperscript/package.json'
import slatePlainSerializer from '../../packages/slate-plain-serializer/package.json'
import slatePropTypes from '../../packages/slate-prop-types/package.json'
import slateReact from '../../packages/slate-react/package.json'
import slateReactPlaceholder from '../../packages/slate-react-placeholder/package.json'
const configurations = [
...factory(slate),
...factory(slateBase64Serializer),
...factory(slateDevEnvironment),
...factory(slateHotkeys),
...factory(slateHtmlSerializer),
...factory(slateHyperscript),
...factory(slatePlainSerializer),
...factory(slatePropTypes),
...factory(slateReact),
...factory(slateReactPlaceholder),
]
export default configurations

View File

@@ -1,148 +0,0 @@
import babel from 'rollup-plugin-babel'
import builtins from 'rollup-plugin-node-builtins'
import commonjs from 'rollup-plugin-commonjs'
import globals from 'rollup-plugin-node-globals'
import json from 'rollup-plugin-json'
import replace from 'rollup-plugin-replace'
import resolve from 'rollup-plugin-node-resolve'
import uglify from 'rollup-plugin-uglify'
import { startCase } from 'lodash'
/**
* Return a Rollup configuration for a `pkg` with `env` and `target`.
*
* @param {Object} pkg
* @param {String} env
* @param {String} format
* @return {Object}
*/
function configure(pkg, env, target) {
const isProd = env === 'production'
const isUmd = target === 'umd'
const isModule = target === 'module'
const input = `packages/${pkg.name}/src/index.js`
const deps = []
.concat(pkg.dependencies ? Object.keys(pkg.dependencies) : [])
.concat(pkg.peerDependencies ? Object.keys(pkg.peerDependencies) : [])
const plugins = [
// Allow Rollup to resolve modules from `node_modules`, since it only
// resolves local modules by default.
resolve({
browser: true,
}),
// Allow Rollup to resolve CommonJS modules, since it only resolves ES2015
// modules by default.
isUmd &&
commonjs({
exclude: [`packages/${pkg.name}/src/**`],
// HACK: Sometimes the CommonJS plugin can't identify named exports, so
// we have to manually specify named exports here for them to work.
// https://github.com/rollup/rollup-plugin-commonjs#custom-named-exports
namedExports: {
esrever: ['reverse'],
immutable: [
'List',
'Map',
'Record',
'OrderedSet',
'Set',
'Stack',
'is',
],
'react-dom': ['findDOMNode'],
'react-dom/server': ['renderToStaticMarkup'],
},
}),
// Convert JSON imports to ES6 modules.
json(),
// Replace `process.env.NODE_ENV` with its value, which enables some modules
// like React and Slate to use their production variant.
replace({
'process.env.NODE_ENV': JSON.stringify(env),
}),
// Register Node.js builtins for browserify compatibility.
builtins(),
// Use Babel to transpile the result, limiting it to the source code.
babel({
include: [`packages/${pkg.name}/src/**`],
}),
// Register Node.js globals for browserify compatibility.
globals(),
// Only minify the output in production, since it is very slow. And only
// for UMD builds, since modules will be bundled by the consumer.
isUmd && isProd && uglify(),
].filter(Boolean)
if (isUmd) {
return {
plugins,
input,
output: {
format: 'umd',
file: `packages/${pkg.name}/${isProd ? pkg.umdMin : pkg.umd}`,
exports: 'named',
name: startCase(pkg.name).replace(/ /g, ''),
globals: pkg.umdGlobals,
},
external: Object.keys(pkg.umdGlobals || {}),
}
}
if (isModule) {
return {
plugins,
input,
output: [
{
file: `packages/${pkg.name}/${pkg.module}`,
format: 'es',
sourcemap: true,
},
{
file: `packages/${pkg.name}/${pkg.main}`,
format: 'cjs',
exports: 'named',
sourcemap: true,
},
],
// We need to explicitly state which modules are external, meaning that
// they are present at runtime. In the case of non-UMD configs, this means
// all non-Slate packages.
external: id => {
return !!deps.find(dep => dep === id || id.startsWith(`${dep}/`))
},
}
}
}
/**
* Return a Rollup configuration for a `pkg`.
*
* @return {Array}
*/
function factory(pkg) {
const isProd = process.env.NODE_ENV === 'production'
return [
configure(pkg, 'development', 'module'),
isProd && configure(pkg, 'development', 'umd'),
isProd && configure(pkg, 'production', 'umd'),
].filter(Boolean)
}
/**
* Export.
*
* @type {Function}
*/
export default factory

View File

@@ -1,101 +0,0 @@
const path = require('path')
const webpack = require('webpack')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const HtmlWebpackTemplate = require('html-webpack-template')
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const CopyWebpackPlugin = require('copy-webpack-plugin')
const UglifyJSPlugin = require('uglifyjs-webpack-plugin')
const DefinePlugin = webpack.DefinePlugin
const NamedModulesPlugin = webpack.NamedModulesPlugin
const HotModuleReplacementPlugin = webpack.HotModuleReplacementPlugin
const IS_PROD = process.env.NODE_ENV === 'production'
const IS_DEV = !IS_PROD
const config = {
entry: [
'babel-polyfill',
// COMPAT: Missing in IE 11 and included separately because babel-polyfill does not support DOM elements:
// https://github.com/zloirock/core-js/issues/317
'element-closest',
'react-hot-loader/patch',
'./examples/index.js',
],
output: {
path: path.resolve(__dirname, '../../build'),
filename: '[name]-[hash].js',
},
devtool: IS_PROD ? 'source-map' : 'inline-source-map',
devServer: {
contentBase: './examples',
publicPath: '/',
hot: true,
host: '0.0.0.0',
},
module: {
rules: [
{
test: /\.js?$/,
use: 'source-map-loader',
enforce: 'pre',
},
{
test: /\.js?$/,
use: {
loader: 'babel-loader',
options: {
forceEnv: 'webpack',
},
},
exclude: /node_modules/,
},
{
test: /\.css$/,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: [
{
loader: 'css-loader',
options: {
sourceMap: true,
},
},
],
}),
},
],
},
plugins: [
new DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(
IS_PROD ? 'production' : 'development'
),
}),
new ExtractTextPlugin('[name]-[contenthash].css'),
new HtmlWebpackPlugin({
title: 'Slate',
template: HtmlWebpackTemplate,
inject: false,
// Note: this is not the correct format meta for HtmlWebpackPlugin, which
// accepts a single object of key=name and value=content. We need to
// format it this way for HtmlWebpackTemplate which expects an array of
// objects instead.
meta: [
{
name: 'viewport',
content: 'width=device-width, initial-scale=1',
},
],
links: [
'https://fonts.googleapis.com/css?family=Roboto:400,400i,700,700i&subset=latin-ext',
'https://fonts.googleapis.com/icon?family=Material+Icons',
],
}),
IS_PROD && new CopyWebpackPlugin(['examples/CNAME']),
IS_PROD && new UglifyJSPlugin({ sourceMap: true }),
IS_DEV && new NamedModulesPlugin(),
IS_DEV && new HotModuleReplacementPlugin(),
].filter(Boolean),
}
module.exports = config